using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class LocationMap : EntityTypeConfiguration<Location>
    {
        public LocationMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.NAME)
                .IsRequired()
                .HasMaxLength(3);

            this.Property(t => t.ACCT)
                .HasMaxLength(40);

            this.Property(t => t.DESCR)
                .HasMaxLength(20);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("Location");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.NAME).HasColumnName("NAME");
            this.Property(t => t.ACCT).HasColumnName("ACCT");
            this.Property(t => t.DESCR).HasColumnName("DESCR");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");
            this.Property(t => t.Division).HasColumnName("Division");
            this.Property(t => t.Site).HasColumnName("Site");

            // Relationships
            this.HasOptional(t => t.Acct1)
                .WithMany(t => t.Locations)
                .HasForeignKey(d => d.ACCT);
            this.HasOptional(t => t.Division1)
                .WithMany(t => t.Locations)
                .HasForeignKey(d => d.Division);
            this.HasOptional(t => t.Site1)
                .WithMany(t => t.Locations)
                .HasForeignKey(d => d.Site);

        }
    }
}
